package com.linkwings.projectsimple.http.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.linkwings.projectsimple.pojo.UserInfo;


@Controller
@RequestMapping("/userinfo")
public class UserInfoController {

	   @RequestMapping(value="/index", method=RequestMethod.GET)  
	   public String index(){  
	     return "/userinfo/list";  
	   }  
	   
	   /*redirect*/
	   @RequestMapping(value="/index2", method=RequestMethod.GET)  
	   public String index2(@RequestParam("tag") String tag,@RequestParam("id") String id,HttpServletRequest request){  
		 request.setAttribute("tag", tag);
		 request.setAttribute("id", id);
	     //return"redirect:/userinfo/index";
		 return "/userinfo/list";  
	   }
	   
	   /*common param and path var param*/
	   @RequestMapping(value="/{id}/show",  method=RequestMethod.GET)  
	   public String show(@PathVariable String id,HttpServletRequest request){ 
		 request.setAttribute("id", id);
		
	     return "/userinfo/view";
	   }
	   
	   
	   /*common param and path var param*/
	   @RequestMapping(value="/{id}/edit",  method=RequestMethod.GET)  
	   public String edit(@PathVariable String id,HttpServletRequest request){ 
		 request.setAttribute("id", id);
	     return "/userinfo/form";
	   }	   
	   
	   /*common param and path var param*/
	   @RequestMapping(value="/{id}",method=RequestMethod.POST)
	   public String save(@RequestParam("tag") String tag,@PathVariable("id") String id,UserInfo user ,HttpServletRequest request){ 
		 //return"redirect:/userinfo/index2?id="+id+"&tag="+tag;
		 //id is null
		 return"redirect:/userinfo/index2?id="+user.getId()+"&tag="+user.getTag();
	   }
}
